package com.bw.finance.utils;


import com.bw.finance.eneity.res.TbMenuRes;

import java.util.ArrayList;
import java.util.List;

public class Tree {
    public static List<TbMenuRes> bulidtree(List<TbMenuRes> list){
        List<TbMenuRes> tree=new ArrayList<TbMenuRes>();
        for (TbMenuRes n:list) {
            if(n.getParentId()==0){
                tree.add(findchild(n,list));
            }
        }
        return tree;
    }
    public static TbMenuRes findchild(TbMenuRes node,List<TbMenuRes> list){
        for (TbMenuRes n:list) {
            if(n.getParentId().equals(node.getId())){
                if(node.getChildren()==null){
                    node.setChildren(new ArrayList<>());
                }
                node.getChildren().add(findchild(n,list));
            }
        }
        return node;
    }
}
